home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / xlisp2.1 / xldist01.zoo / lsp / conversi.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1990-11-09  |  1020 b   |  37 lines

  1. ;; These functions are useful for conversion with strings and arrays
  2. ;; Written by Tom Almy
  3.  
  4. ; convert array to list
  5. (defun array-list (array)
  6.     (let ((x nil) (l (length array)))
  7.          (dotimes (n l)
  8.                    (setq x (cons (aref array (- l n 1)) x)))
  9.              x))
  10.  
  11. ; convert list to array
  12. (defun list-array (list)
  13.     (apply #'vector list))
  14.  
  15. ; convert string to list of characters
  16. (defun string-list (string)
  17.     (get-output-stream-list (make-string-input-stream string)))
  18.  
  19. ; convert list of characters to a string
  20. (defun list-string (list)
  21.     (let ((stream (make-string-output-stream)))
  22.          (dolist (each list (get-output-stream-string stream))
  23.              (write-char each stream))))
  24.  
  25.  
  26. ; do over an array
  27. (defmacro doarray (arglist &rest body)
  28.     (let ((sym (first arglist))
  29.           (array (second arglist))
  30.           (returns (cddr arglist))
  31.           (bind (gensym))
  32.           (n (gensym)))
  33.          `(let ((,bind ,array) ,sym)
  34.            (dotimes (,n  (length ,bind) ,@returns)
  35.              (setf ,sym (aref ,bind ,n))
  36.              ,@body))))
  37.